<template>
<div class="mingxi">

  <h2>对账明细查询</h2>

  <div style="width: 1430px;margin-left: 50px">

  <el-form :model="form" :inline="true" >
    <el-form-item label="渠道名称">
      <el-input v-model="form.tradeQudao" clearable></el-input>
    </el-form-item>
    <el-form-item label="对账批次">
      <el-input v-model="form.batchNo" clearable></el-input>
    </el-form-item>
    <el-form-item label="交易结果">
      <el-select v-model="form.tradeResult" clearable>
        <el-option label="处理中" value="1"></el-option>
        <el-option label="成功" value="2"></el-option>
        <el-option label="失败" value="3"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="交易金额">
      <el-input v-model="form.amount" clearable></el-input>
    </el-form-item>
    <el-form-item label="是否差错">
      <el-select v-model="form.hasDiff" clearable>
        <el-option label="否" value="0"></el-option>
        <el-option label="是" value="1"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="交易日期:">
      <el-date-picker
        clearable
        v-model="form.startDate"
        value-format="yyyy-MM-dd"
        placeholder="选择日期">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="至">
      <el-date-picker
        clearable
        v-model="form.endDate"
        value-format="yyyy-MM-dd"
        placeholder="选择日期">
      </el-date-picker>
    </el-form-item><br>
    <el-form-item label="处理结果">
      <el-select v-model="form.processState" clearable>
        <el-option label="未处理" value="1"></el-option>
        <el-option label="要结算" value="2"></el-option>
        <el-option label="不结算" value="3"></el-option>
        <el-option label="已处理" value="4"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="支付方式">
      <el-select v-model="form.payWay" clearable>
        <el-option label="微信扫码" value="1"></el-option>
        <el-option label="支付宝扫码" value="2"></el-option>
        <el-option label="微信公众号" value="3"></el-option>
        <el-option label="认证支付" value="4"></el-option>
        <el-option label="实时代付到银行卡" value="5"></el-option>
        <el-option label="批量代付到银行卡" value="6"></el-option>
      </el-select>
    </el-form-item>

    <el-form-item>
      <el-button type="warning" @click="initData()">查询</el-button>
    </el-form-item>
  </el-form>

    <el-table
      :data="tableData"
      style="border: 1px solid black">
      <el-table-column
        prop="batchNo"
        label="对账批次"
        width="180">
      </el-table-column>
      <el-table-column
        prop="payOrderNo"
        label="交易流水号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="qudaoOrderNo"
        label="渠道订单号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="tradeQudao"
        label="渠道名称"
        width="180">
      </el-table-column>
      <el-table-column
        label="交易结果">
        <template slot-scope="scope">
          <span v-if="scope.row.tradeResult==1">处理中</span>
          <span v-if="scope.row.tradeResult==2">成功</span>
          <span v-if="scope.row.tradeResult==3">失败</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="amount"
        label="交易金额">
      </el-table-column>
      <el-table-column
        prop="tradeDateZf"
        label="交易日期">
      </el-table-column>
      <el-table-column
        prop="commissionFee"
        label="手续费">
      </el-table-column>
      <el-table-column
        label="支付方式">
        <template slot-scope="scope">
          <span v-if="scope.row.payWay==1">微信扫码</span>
          <span v-if="scope.row.payWay==2">支付宝扫码</span>
          <span v-if="scope.row.payWay==5">实时代付到银行卡</span>
          <span v-if="scope.row.payWay==4">认证支付</span>
          <span v-if="scope.row.payWay==3">微信公众号</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="tradeAccount"
        label="交易账号">
      </el-table-column>
      <el-table-column
        prop="tradeAccountTypeName"
        label="交易账户类型">
      </el-table-column>
      <el-table-column
        label="是否差错">
        <template slot-scope="scope">
          <span v-if="scope.row.hasDiff==0">否</span>
          <span v-if="scope.row.hasDiff==1">是</span>
        </template>
      </el-table-column>
      <el-table-column
        label="处理结果">
        <template slot-scope="scope">
          <span v-if="scope.row.processState==3">不结算</span>
          <span v-if="scope.row.processState==2">要结算</span>
          <span v-if="scope.row.processState==1">未处理</span>
          <span v-if="scope.row.processState==4">已处理</span>
          <span v-if="scope.row.processState==0"></span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <span v-if="scope.row.processState==1">
            <el-button @click="processCheckDiff(scope.row.id,scope.row.payWay,scope.row.batchNo,scope.row.canClearingAmount)">处理</el-button>
          </span>
        </template>
      </el-table-column>


    </el-table><br>

<!--    <el-button type="warning">重新对账</el-button>-->
    <el-button type="success" @click="checkBatchConfirm">对账确认</el-button>

  </div>

</div>
</template>

<script>
import {allList,ajaxProcessCheckDiff,checkBatchConfirm} from "@/api/wishu/mingxi";

export default {
  name: "mingxi",
  data(){
    return{
      form:{
        batchNo:'20230508002'
      },
      tableData:[],

    }
  },
  created() {
    this.initData();
  },
  methods:{
    initData(){
      allList(this.form).then((res)=>{
        this.tableData=res;
      })
    },
    processCheckDiff(batchId,payWay,batchNo,canClearingAmount){
      if(confirm("是否要进行差错处理")) {
          var payWayNum = null;
          if (payWay != 0) {
            //if(payWay < 5){
            // 有商户可结算金额，并且金额大于0的时候
            if (canClearingAmount != '' && canClearingAmount > 0) {
              if(confirm("是否需要结算")) {
                payWayNum = 2;
                //alert(payWayNum);
                this.ajaxProcessCheckDiff(batchId, payWayNum, batchNo);
              }
                payWayNum = 3;
                //alert(payWayNum);
              this.ajaxProcessCheckDiff(batchId, payWayNum, batchNo);

              //}else if (payWay == 5){
            } else {  // 无结算金额的时候，线下处理完差错，线上只修改一下处理状态，无需结算
              payWayNum = 0;
              //alert(payWayNum);
              this.ajaxProcessCheckDiff(batchId, payWayNum, batchNo);
            }
        }
      }
    },
    ajaxProcessCheckDiff(batchId,payWayNum,batchNo){
      ajaxProcessCheckDiff(batchId,payWayNum,batchNo).then((res)=>{
        if(res){
          this.initData();
          this.$message.success('成功');
        }else{
          this.$message.success('失败');
        }
      })
    },
    checkBatchConfirm(){
      checkBatchConfirm(this.form.batchNo).then((res)=>{
        if(res.flag){
          this.initData();
          this.$message.success('确认对账成功');
        }else{
          this.$message.error(res.msg);
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
